package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ShopStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@ResponseBody
@Slf4j
@Api(tags = "后台-店铺营业状态的相关接口")
@CrossOrigin//解决跨域问题
public class ShopStatusController {
    @Autowired
    private ShopStatusService shopStatusService;//注入店铺营业状态服务对象
    //注入redisTemplate模版对象用来操作redis缓存数据
    @Autowired
    private RedisTemplate redisTemplate;
    //创建一个常量,用来存放redis缓存的key值
    public static final String SHOP_STATUS_KEY = "shop_status";


    /**
     * 网页管理端-获取店铺营业状态
     */
    @ApiOperation(value = "获取店铺营业状态", notes = "获取店铺营业状态")
    @GetMapping("/admin/shop/status")
    public Result<Integer> getShopStatus() {
        //1.记录日志
        log.info("获取店铺营业状态");
        //2.业务获取店铺营业状态
        Integer shopStatus = shopStatusService.getShopStatus();
        //2.5.从redis缓存中获取店铺营业状态
        //Integer shopStatus = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS_KEY);

        //3.返回统一的响应结果对象result
        return Result.success(shopStatus);
    }




    /**
     * 设置店铺营业状态<br>
     * <a id=设置营业状态> </a>
     * 基本信息
     *<p>
     * Path：/admin/shop/{status}
     *<p>
     *Method： PUT
     */
    @ApiOperation(value = "设置店铺营业状态", notes = "设置店铺营业状态")
    @PutMapping("/admin/shop/{status}")
    public Result<String> updateShopStatus(@PathVariable Integer status) {
        //1.记录日志
        log.info("设置店铺营业状态为：" + status);
        //2.业务设置店铺营业状态
        shopStatusService.sethopStatus(status);
        //3.返回统一的响应结果对象result
        return Result.success("设置店铺营业状态成功");

    }
}
